package com.collabscm.md.base.model;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EntityResult;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.NamedNativeQueries;
import javax.persistence.NamedNativeQuery;
import javax.persistence.NamedQueries;
import javax.persistence.SqlResultSetMapping;
import javax.persistence.SqlResultSetMappings;
import javax.persistence.Table;

import com.collabscm.pf.model.DomainObject;

/**
 * 系统业务参数，某些业务参数是可以修改，某些是不能修改，其中不能修改的部分作为系统的常量。
 * 
 * @author Zeng Raoxing
 */
@Table(name = "t_md_parameter")
@NamedQueries ({
})
@NamedNativeQueries ({
	//查询系统定义的常量值
	@NamedNativeQuery(name=Parameter.findBusinessContantsName, 
			query="select Param_ID, Param_Category, Param_Code from t_md_parameter where Modify_Category=1 and Status=2001",
			resultSetMapping="constantMapping")
})
//系统常量返回后的映射
@SqlResultSetMappings ({
	@SqlResultSetMapping (
		name="constantMapping",
		entities={
			@EntityResult(
				entityClass=Parameter.Constant.class 
//				,fields={
//					@FieldResult(name="parameterId", column="Param_ID"), 
//					@FieldResult(name="parameterCategory", column="Param_Category"),
//					@FieldResult(name="parameterCode", column="Param_Code")
//				}
			)
		}
	)
})
@Entity public class Parameter extends DomainObject {
	private static final long serialVersionUID = 1L;
	/**
	 * 业务常量，是modifyCategory的取值之一，即不可以手工删除和增加，这类型的常量都是在系统中定义过这个常量的。
	 */
	public static final Integer BUSINESS_CONSTANT = 1;
	/**
	 * 查询有效的参数列表，用于初始化系统中的业务常量
	 */
	public static final String findBusinessContantsName = "Parameter.findBusinessContants";
//	private static final String parameterIdColumn = "Param_ID";
//	private static final String parameterCategoryColumn = "Param_Category";
//	private static final String parameterCodeColumn = "Param_Code";
//	private static final String modifyCategoryColumn = "Modify_Category"; 
//不能在Annotation不能如此定义常量，因此将此处相关的东东都注释掉了。
//	private static final String findBusinessContantsSQL = "select " +parameterIdColumn+ "," +parameterCategoryColumn+ "," + parameterCodeColumn
//    			+ " from t_md_parameter where " + modifyCategoryColumn + "=" + BUSINESS_CONSTANT;
	//将在NamedNativeQuery中定义的数据库字段名定义出来，防止将来数据库字段名修改，但对应的地方还未修改

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(name = "Param_ID", unique = true, nullable = false, precision = 10)
	private Integer parameterId;

	/**
	 * 参数分类
	 */
	@Column(name = "Param_Category", nullable = false, length = 60)
	private String parameterCategory;

	/**
	 * 参数代码
	 */
	@Column(name = "Param_Code", nullable = false, length = 60)
	private String parameterCode;

	/**
	 * 参数中文名
	 */
	@Column(name = "Param_Name_zh_CN", nullable = false, length = 60)
	private String parameterNameZhCN;

	/**
	 * 参数英文名
	 */
	@Column(name = "Param_Name_en", nullable = false, length = 60)
	private String parameterNameEn;

	// 数据库预留字段，因此不需要在页面维护，如果将来确定了语言，
	// 那么将Lang1可以直接修改为对应的语言名称
	// @Column(name="Param_Name_Lang1", length=60)
	// private String parameterName_Lang1;
	//
	// @Column(name="Param_Name_Lang2", length=60)
	// private String parameterName_Lang2;
	//
	// @Column(name="Param_Name_Lang3", length=60)
	// private String parameterName_Lang3;
	//
	// @Column(name="Param_Name_Lang4", length=60)
	// private String parameterName_Lang4;
	//
	// @Column(name="Param_Name_Lang5", length=60)
	// private String parameterName_Lang5;

	/**
	 * 父节点ID
	 */
	@Column(name = "Parent_Param_ID", precision = 10)
	private Integer parentParameterId;
	
	/**
	 * 是否有孩子?
	 */
	@Column(name="Has_Child", precision = 1)
	private Integer hasChild;

	/**
	 * 维护类型
	 */
	@Column(name = "Modify_Category", nullable = false)
	private Integer modifyCategory;
	
	// Setter/Getter
	public Integer getParameterId() {
		return parameterId;
	}

	public void setParameterId(Integer parameterId) {
		this.parameterId = parameterId;
	}

	public String getParameterCategory() {
		return parameterCategory;
	}

	public void setParameterCategory(String parameterCategory) {
		this.parameterCategory = parameterCategory;
	}

	public String getParameterCode() {
		return parameterCode;
	}

	public void setParameterCode(String parameterCode) {
		this.parameterCode = parameterCode;
	}

	public String getParameterNameZhCN() {
		return parameterNameZhCN;
	}

	public void setParameterNameZhCN(String parameterNameZhCN) {
		this.parameterNameZhCN = parameterNameZhCN;
	}

	public String getParameterNameEn() {
		return parameterNameEn;
	}

	public void setParameterNameEn(String parameterNameEn) {
		this.parameterNameEn = parameterNameEn;
	}

	public Integer getParentParameterId() {
		return parentParameterId;
	}

	public void setParentParameterId(Integer parentParameterId) {
		this.parentParameterId = parentParameterId;
	}

	public Integer getHasChild() {
		return hasChild;
	}

	public void setHasChild(Integer hasChild) {
		this.hasChild = hasChild;
	}

	public Integer getModifyCategory() {
		return modifyCategory;
	}

	public void setModifyCategory(Integer modifyCategory) {
		this.modifyCategory = modifyCategory;
	}
	
	/**
	 * 出书新建的是为了能够将系统常量进行Mapping，如果直接使用Parameter对象的话将引起对其他映射的值进行
	 * 赋值，因此就单独写了一个内部类，用于此工作。
	 * 不过此处的定义确实比较重复！
	 *
	 * @author Zeng Raoxing
	 */
	@Entity	public static class Constant {
		@Id
		@Column(name = "Param_ID", unique = true, nullable = false, precision = 10)
		private Integer parameterId;

		/**
		 * 参数分类
		 */
		@Column(name = "Param_Category", nullable = false, length = 60)
		private String parameterCategory;

		/**
		 * 参数代码
		 */
		@Column(name = "Param_Code", nullable = false, length = 60)
		private String parameterCode;
		
		public Integer getParameterId() {
			return parameterId;
		}

		public void setParameterId(Integer parameterId) {
			this.parameterId = parameterId;
		}

		public String getParameterCategory() {
			return parameterCategory;
		}

		public void setParameterCategory(String parameterCategory) {
			this.parameterCategory = parameterCategory;
		}

		public String getParameterCode() {
			return parameterCode;
		}

		public void setParameterCode(String parameterCode) {
			this.parameterCode = parameterCode;
		}
	}

}
